package com.dqp.cslggroup.School;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;

import com.dqp.cslggroup.ConnectSever.Send;
import com.dqp.cslggroup.R;
import com.dqp.cslggroup.UI.BaseActivity;
import com.dqp.cslggroup.Util.ToastUtil;

import java.util.Objects;

public class club_submit extends BaseActivity {
    private boolean flag = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.club_submit);
        Toolbar toolbar = findViewById(R.id.include_toolbar);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
        initCom();

    }

    public void initCom() {
        TextView button = findViewById(R.id.club_submit_button);
        EditText name = findViewById(R.id.club_submit_name);
        EditText level = findViewById(R.id.club_submit_level);
        EditText qq = findViewById(R.id.club_submit_qq);
        EditText des = findViewById(R.id.club_submit_eid);
        button.setOnClickListener(v -> {
            if (flag) {
                String names = name.getText().toString();
                String levels = level.getText().toString();
                String qqs = qq.getText().toString();
                String s = des.getText().toString();
                if (qq.length() > 7 & level.length() > 0 & name.length() > 0) {
                    if (des.length() > 10) {
                        new Thread(() -> {
                            if (Send.putClubSubmit(names, levels, qqs, s)) {
                                flag = false;
                                finish();
                                ToastUtil.showToast("提交成功！");

                            } else ToastUtil.showToast("提交失败！");
                        }).start();
                    } else ToastUtil.showToast("介绍必须大于10个字！");
                } else ToastUtil.showToast("信息填写不完善！");
            } else ToastUtil.showToast("请勿连续提交！");
        });

    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
